package handler;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

//TODO:授权码激活操作
@WebServlet(name = "checkAu", value = "/checkAu")
public class checkAu extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;utf-8");
        PrintWriter out =resp.getWriter();
        String use_au=req.getParameter("use_au");
        try {
            if (Refresh.checkstate(use_au)==0){
                Refresh.refresh_state2(use_au);
                out.print("激活成功！");
            }else if (Refresh.checkstate(use_au)==1){
                out.print("该授权码已被激活");
            }else {
                out.print("授权码不存在");
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}